App.controller("interfaceManagementCtrl",function($scope, $rootScope, $location, $http, $compile, $stateParams, $timeout, path, publicService) {
	var limitParam = {imageSize:200, format:"jpg"};		//封面图
	//获取模板内容
	$scope.urlsRquest = function(){
		$http({
			   url: path+"/server/selectIsFirstUpload",
			    method: 'GET',
		}).success(function(data){
			if(data.result){
				publicService.showUploadImage("upload1_img2","upload1_url2",data.result.activity_url);  //活动分享
				publicService.showUploadImage("upload1_img3","upload1_url3",data.result.invitation_url);  //邀请好友
			}
		});
	};	

	//上传图片（单个）
	$scope.uploadImage = function(containerId,imgId,imgUrlId,urls,limitParam){
		$("#"+containerId).kendoUpload({
	        async: {
	            saveUrl: path+"/common/"+urls,
	        },
	     	multiple: false,      //多选
	      	showFileList: false,  //显示文件列表
	        localization: {
	              select: "请上传图片",
	              cancel: "取消",
	              remove: "移除",  //autoUpload: false
	              retry: "刷新",
	              headerStatusUploading: "上传...",
	              headerStatusUploaded: "上传成功",
	              statusUploading: "loading",
	              statusUploaded: "success",
	              statusFailed: "failed",
	              uploadSelectedFiles: "上传选中的文件",   //autoUpload: false
	        },
	        success: function(e){
	        	if(e.response.code =="0"){
	        		var ss = Math.random();
	        		var url = e.response.result+"?"+ss;   //图片路径
		        	publicService.showUploadImage(imgId,imgUrlId,url);
	        	}else if(e.response.code =="1"){
	        		alert(e.response.message);
	        		return;
	        	}
	        	
		    },
	        error: function(e){
	        	//alert('失败！');
	        },
	        remove: function(e){
	        	//alert('移除！');
	        },
	        select: function(e){	//选择
	        	var image = e.files[0];
	        	if(limitParam){
	        		if(limitParam.imageSize && image.size>(limitParam.imageSize*1024)){
		        		alert("上传图片的大小请限制在【"+limitParam.imageSize+"Kb】以内！");
		        		e.preventDefault();
		        		return;
		        	}
	        		if(limitParam.format && limitParam.format.indexOf(image.extension.substr(1,image.extension.length).toLowerCase())==-1){
		        		alert("上传图片仅支持【"+limitParam.format+"】格式！");
		        		e.preventDefault();
		        		return;
		        	}
	        	}
	        }
	    });
	};
	//模板案例下载
	$scope.caseDown = function(){
		window.location.href = path+"/common/download?name=模板.jpg";
	}
	//提交两个库
	$scope.submit = function(){
		var upload1_url2 = $('#upload1_url2').val();
		var upload1_url3 = $('#upload1_url3').val();
		if(upload1_url2&&upload1_url3){
			var pramOBject = {
			    	"activity_url":upload1_url2,
			    	"invitation_url":upload1_url3,
			};
			$http({
				   url: path+"/server/insertInterfaceManagementTemplateUrl",
				    method: 'post',
				    data:angular.toJson(pramOBject),
			}).success(function(data){
				if(data.code =="0"){
					alert("上传成功！");
					window.location.reload();
				}else if(data.code =="1"){
					alert("接口报错！请联系服务员！");
				}
			}).error(function(data){
			alert(data);   
		});
		}else{
			alert('活动分享模板和邀请好友模板都上传以后才可以上传！');
		}
	};
	$scope.uploadImage("cover2","upload1_img2","upload1_url2","updoadInterfaceActivityImg",limitParam);
	$scope.uploadImage("cover3","upload1_img3","upload1_url3","updoadInterfaceInvitationImg",limitParam);
	$scope.urlsRquest();   //首次进入获取
});